<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>商品分类管理</title>
    <#include "../common/header.ftl"/>
    <#include "../common/page.ftl"/>

    <script type="text/javascript">
        $(function () {
// 推荐数据回显
            $('.inputBtn').click(function() {
                $('#editForm')[0].reset();
                $('#editForm img').attr('src','');
                var data = $(this).data('json');
                if(data){
                    $('#editForm input[name="id"]').val(data.id);
                    $('#editForm input[name="name"]').val(data.name);
                    $('#editForm input[name="imageUrl"]').val(data.imageUrl);
                    $('#editForm img').attr('src',data.imageUrl);
                }
                    $('#editModal').modal('show');

            });
            // 图片更换是回显
            $('#editForm input[name="file"]').change(function () {
                // 创建文件读取器对象
                var read = new FileReader();
                // 读取文件内容
                read.readAsDataURL(this.files[0]);
                // 将用户选择的图片渲染到页面
                $(read).load(function () {
                    $('#editForm img').attr('src',read.result);
                });
            });
            // 推荐操作
            $('.btn_submit').click(function () {
                $('#editForm').ajaxSubmit( function(data){
                        if(data.success){
                           window.location.reload();
                        } else {
                            $.messager.alert("温馨提示","操作失败!");
                        }

                });
            });
        $('.deleteBtn').click(function () {
            var itemCatalogId = $(this).data("id");
            $.post('/itemCatalog/delete.do',{itemCatalogId:itemCatalogId},function (data) {
                if(data.success){
                    window.location.href = '/itemCatalog/list.do';
                } else {
                    $.messager.alert("温馨提示","删除失败!");
                }
            });
        });
        });
    </script>
</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-2">
		<#assign currentMenu = "item_catalog" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-10">
            <div class="page-header">
                <h3>商品分类管理</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/itemCatalog/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                    </div>
                    <div class="form-group">
                        <label>关键字</label>
                        <input class="form-control" type="text" name="keyword" placeholder="请输入标题/昵称"  value="${(qo.keyword)!''}">
                    </div>
                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                        <button type="button" class="btn btn-success inputBtn"><i class="icon-plus"></i> 添加</button>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>商品分类名称</th>
                        <th>商品分类图片</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
					<#list result.list as vo>
                    <tr>
                        <td>${vo_index + 1}</td>
                        <td>${(vo.name)!}</td>
                        <td><img src="${vo.imageUrl!}" style="width: 60px" alt=""></td>
                        <td>
                            <a href="javascript:;" class="btn btn-success inputBtn" data-json='${vo.jsonString!}'>修改</a>
                            <a href="javascript:;" data-id="${vo.id!}" class="btn btn-danger deleteBtn">删除</a>
                        </td>
                    </tr>
					</#list>
                    </tbody>
                </table>

                <div style="text-align: center;">
                <ul id="pagination" class="pagination"></ul>
            </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑/添加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/itemCatalog/saveOrUpdate.do" method="post" id="editForm" >
                    <input type="hidden" value="" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">商品分类名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">商品分类图片 ：</label>
                        <div class="col-sm-6">
                            <img  style="width: 250px;"/>
                            <input type="file" class="form-control" name="file">
                            <input type="hidden" class="form-control" name="imageUrl">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn_submit">保存</button>
                <button type="button" class="btn btn-danger" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>